package com.shelpe.services.scheduler.item.category;

import java.util.List;

import org.springframework.batch.item.ItemProcessor;
import org.springframework.beans.factory.annotation.Autowired;

import com.shelpe.services.scheduler.dto.CatDataDto;
import com.shelpe.services.scheduler.po.Category;
import com.shelpe.services.scheduler.po.SyncLog;
import com.shelpe.services.scheduler.syncclient.CategoryClient;
import com.shelpe.services.scheduler.util.Util;


public class CategoryProcessor implements ItemProcessor<List<Category>, SyncLog>{

	@Autowired
	private CategoryClient categoryClient;
	
	@Override
	public SyncLog process(List<Category> item) throws Exception {
		// TODO Auto-generated method stub
		SyncLog log = null;
		
		if(item != null && item.size() > 0){
			StringBuilder sb = new StringBuilder();
			int length = item.size() - 1;
			for(int index = 0; index < length; index++){
				Category cat = item.get(index);
				sb.append(cat.getCatId());
				sb.append(",");
			}
			Category catLast = item.get(length);
			sb.append(catLast.getCatId());
			CatDataDto dto = categoryClient.syncInsightCategoryData(sb.toString());
			log = Util.convert(dto);
		}
		
		return log;
	}

	
	
}
